const express = require('express')

const morgan = require('morgan')

const cors = require('cors')

const router = require('./router')

const errorHandler = require('./middleware/errorHandler')

const app = express()

const PORT = process.env.PORT || 9000

// 挂载日志输出中间件
app.use(morgan('dev'))

// 处理body携带的json数据
app.use(express.json())

// 允许跨域
app.use(cors())

// 挂载路由
app.use(router)

// 错误处理中间件
app.use(errorHandler())

app.listen(PORT, () => {
  console.log(`App listening on port ${PORT}`)
})